"""
* 这是一道二分，(差分/区间合并)题
* 用区间合并的方式来会比较快
* 不仅如此这还是一道 离散化 的 区间合并（这部分洛谷找不到合适的平替模板题）
https://www.acwing.com/problem/content/5410/
"""
def resolution1():
    number, length = map(int, input().split())
    locations = [0] * (number+2)
    start_times = [0] * (number+2)
    for i in range(1, number+1):
        locations[i], start_times[i] = map(int, input().split())

    # 在所有可能满足条件的时刻线列表中进行二分查找，找到能满足条件的最早时间
    left = 0
    # ！！！从最坏的情况来考虑漫延的时间，应该是在最一端漫延到最另一段，然后最早开始的时间是Si的最大值，管道的距离是len的最大值，
    # 所以最终得到right的极值应该是2 * 10^9
    right = max(start_times) + length
    while left < right:
        mid = left + (right - left) >> 1
        if check(mid, number, length, locations, start_times):
            right = mid
        else:
            left = mid + 1
    if left == right:
        print(left)

def check(mid, number, length, locations, start_times):
    # 构建出mid时刻下的每一个阀门当前漫过的左右界
    # ！！！需要判断一下当前的时刻该阀门是否已经开始漫延
    left_bounds = [0] * (number+2)
    right_bounds = [0] * (number+2)
    for i in range(1, number+1):
        if mid >= start_times[i]:
            left_bounds[i] = locations[i] - (mid - start_times[i])
            if left_bounds[i] < 1:
                left_bounds[i] = 1
            right_bounds[i] = locations[i] + (mid - start_times[i])
            if right_bounds[i] > length:
                right_bounds[i] = length
        else:
            # 否则可以忽略当前这个阀门
            left_bounds[i] = right_bounds[i] = 0
    # 构建漫延数组的差分数组：
    differs = [0] * (length + 3)
    for i in range(1, number+1):
        differs[left_bounds[i]] += 1
        differs[right_bounds[i] + 1] += 1
    # 由差分数组倒退漫延数组并判断当前时刻是否水流已经漫延到整个管道
    floods = [0] * (length + 2)
    for i in range(1, length + 1):
        floods[i] = floods[i - 1] + differs[i]
        if floods[i] == 0:
            return False
    return True


if __name__ == '__main__':
    resolution1()